//
//  HMVisitorTableViewController.swift
//  WeiBo
//
//  Created by Feng on 2017/6/5.
//  Copyright © 2017年 feng. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController {

    //设置是否登录标记
    var isLogin: Bool = HMUserAccountViewModel.sharedUserAccount.isLogin
//    var isLogin: Bool = false
    
    //设置全局visitorView
    var visitorView: HMVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    //重写loadView
    override func loadView() {
        
        if isLogin
        {
            //已经登录
            super.loadView()
        }
        else
        {
            //没有登录
            setupUI()
            
            visitorView = HMVisitorView()
            
            //设置回调
            visitorView?.callBack = {
                self.buttonClick()
            }
            view = visitorView
        }
    }
    
    func setupUI()
    {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(leftBarButtonItemClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(rightBarButtonItemClick))
    }
    
    //按钮点击方法
    func leftBarButtonItemClick()
    {
        print("注册被点击")
        
        buttonClick()
    }
    
    func rightBarButtonItemClick()
    {
        print("登录被点击")
        
        buttonClick()
    }
    
    func buttonClick()
    {
        let OAuthVC = HMOAuthViewController()
        
        let nav = HMCustomNavigationController(rootViewController: OAuthVC)
        
        self.present(nav, animated: true, completion: nil)
    }

}
